package com.qdlc.p2p.biz.executer.impl;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.executer.BaseExecuter;
import com.qdlc.p2p.biz.service.UserRedEnvelopeService;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.LogTplNid;
import com.qdlc.p2p.common.util.BeanUtil;
import com.qdlc.p2p.dal.dto.BondTender;
import com.qdlc.p2p.dal.util.SystemConfigs;

/**
 * 债权转让购买使用红包
 *
 * @author ylx
 * @version 2.0
 * @date 2015年5月19日 下午5:32:06
 */
@Service
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RedEnvelopeBondTenderExecuter extends BaseExecuter {

    @Override
    public void handleAccountWithLog() {
		Global.setTransfer(LogTplNid.LOG_TPL_KEY, LogTplNid.RED_ENVELOPE_BOND_TENDER);
		Global.setTransfer("web_url", WEB_URL);
		accountService.addUseMoneyAndTotal(super.user.getUserId(), SystemConfigs.ADMIN_ID, super.money);
    }

    @Override
    public void extend() {
        // 获取投标对象
        Object obj = Global.getTransfer().get("bondTender");
        // 获取红包ID
        Object idsObj = Global.getTransfer().get("redEnvelopeIds");
        if (obj != null) {
            BondTender tender = (BondTender) obj;
            long[] redEnvelopeIds = (long[]) idsObj;
            UserRedEnvelopeService userRedEnvelopeService = (UserRedEnvelopeService) BeanUtil
                    .getBean("userRedEnvelopeService");
            userRedEnvelopeService.tenderBondUseRedEnvelope(tender, redEnvelopeIds);
        }
    }
}
